	<script>
import {
  clientEvent
} from '@/common/index/utils/ClientEvent.js'
import { KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_BOTTOM, KEY_ENTER, KEY_DOWN, KEY_BACK, CHOICE_KEY_BACK, CHOICE_KEY_ENTER } from '@/common/index/config/Event'
import { isShow } from "@/common/index/utils/toast.js"
export default {
  onLaunch: function () {
    console.log('App Launch')
    this.plusHandle()
  },
  onShow: function () {
    console.log('App Show')
  },
  onHide: function () {
    console.log('App Hide')
  },

  methods: {
    /**
     * 绑定遥控器事件
     */
    bindKeyEvent () {
      const TvControl = uni.requireNativePlugin("Tv-Control")
      TvControl?.watch({}, result => {
        //异常情况
        if (result.error) {
          return
        }
        if (isShow()) {
          if (result.data.keyName) {
            let {
              keyName,
              keyCode
            } = result.data
            this.CHOICE_KEY_BACK, CHOICE_KEY_ENTER
            if (keyName === 'onKeyBack') {
              //返回键
              clientEvent.dispatchEvent(CHOICE_KEY_BACK, [result.data])
            } else if (keyName === 'onKeyEnter') {
              //确认键
              clientEvent.dispatchEvent(CHOICE_KEY_ENTER, [result.data])
            }
          }
          return
        }
        if (result.data.keyName) {
          let {
            keyName,
            keyCode
          } = result.data

          clientEvent.dispatchEvent(KEY_DOWN, [result.data])
          if (keyName === 'onKeyBack') {
            //返回键
            clientEvent.dispatchEvent(KEY_BACK, [result.data])
          } else if (keyName === 'onKeyEnter') {
            //确认键
            clientEvent.dispatchEvent(KEY_ENTER, [result.data])
          } else if (keyName === 'onKeyLeft') {
            //向左键
            clientEvent.dispatchEvent(KEY_LEFT, [result.data])
          } else if (keyName === 'onKeyRight') {
            //向右键
            clientEvent.dispatchEvent(KEY_RIGHT, [result.data])
          } else if (keyName === ('onKey' + 'Up')) {
            //向上键
            clientEvent.dispatchEvent(KEY_UP, [result.data])
          } else if (keyName === ('onKey' + 'Down')) {
            //向下键
            clientEvent.dispatchEvent(KEY_BOTTOM, [result.data])
          } else if (keyName === 'onKeyMenu') {
            //菜单键
          } else {
            //其他键
          }
        }
      })

    },
    plusHandle () {
      try {
        if (plus) {
          this.bindKeyEvent()
        }
      } catch (e) {

      }
    }
  }
}
</script>

<style>
@media (prefers-color-scheme: dark) {
  :root {
    --color-background: var(--vt-c-black);
    --color-background-soft: var(--vt-c-black-soft);
    --color-background-mute: var(--vt-c-black-mute);

    --color-border: var(--vt-c-divider-dark-2);
    --color-border-hover: var(--vt-c-divider-dark-1);

    --color-heading: var(--vt-c-text-dark-1);
    --color-text: var(--vt-c-text-dark-2);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  position: relative;
  font-weight: normal;
}

body {
  min-height: 100vh;
  color: var(--color-text);
  background: var(--color-background);
  transition: color 0.5s, background-color 0.5s;
  line-height: 1.6;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue",
    sans-serif;
  font-size: 15px;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: white;
}

* {
  margin: 0px;
  padding: 0;
  list-style: none;
  text-decoration: none;
  color: black;
}

body,
#app {
  width: 100vw;
  height: 100vh;
}

.header {
  margin: 2vw auto;
  text-align: center;
  font-size: 4vw;
  font-weight: 400;
  flex-shrink: 0;
}

.mask {
  width: 100vw;
  height: 100vh;
  z-index: 25;
  position: fixed;
  top: 0;
  left: 0;
}

/* 平板尺寸 10.5~12.9寸 */
@media (min-width: 1000px) and (min-height: 1000px) and (max-width: 1300px) and (max-height: 1500px) {
  body,
  #app {
    width: 100vw;
    height: 100vh;
  }
}
</style>
